import { reportData } from "../network-handler";
function domReplace() {
  document.addEventListener(
    "click",
    ({ target }) => {
      const tagName = target.tagName.toLowerCase();
	  // 如果点到了body上，就忽略
      if (tagName === "body") {
        return null;
      }

      let classNames = target.classList.value;
      classNames = classNames !== "" ? `class="${classNames}"` : "";
      const id = target.id ? `id="${target.id}"` : "";
      const innerText = target.innerText;

      // 获取由id、class、innerText字符串组成的标签
      let dom = `<${tagName}${id}${classNames}>${innerText}<${tagName}>`;

      // 上报到后台
      reportData({
        type: "Click",
        dom,
      });
    },
    true
  );
}

export default domReplace
